package com.ds.robot.assistant.controller.api;

import com.ds.robot.assistant.common.R;
import com.ds.robot.assistant.enums.MetricType;
import com.ds.robot.assistant.service.MetricService;
import com.ds.robot.assistant.vo.resp.SeriesData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * 作用：
 *
 * @author WeiShaoying
 * 
 */
@RestController
@RequestMapping("/api/metric")
@Slf4j
public class MetricController {

    @Autowired
    private MetricService metricService;

    @GetMapping("/queryCoreMetricData")
    public R queryCoreMetricData(Integer metricType) {
        MetricType metricTypeEnum = MetricType.getByValue(metricType);
        List<SeriesData> seriesData = metricService.queryCoreMetricData(Optional.ofNullable(metricTypeEnum).orElse(MetricType.CLIENT));
        return R.ok().put("data", seriesData);
    }

}
